#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "matrix.h"

double* transpose(double *matrix, int rows, int cols) 
{
    double *transposed = (double *)malloc(cols * rows * sizeof(double));
    if (transposed == NULL) 
	{
        printf("内存分配失败 \n");
        exit(1);
    }
    
    for (int i = 0; i < rows; i++) 
	{
        for (int j = 0; j < cols; j++) 
		{
            transposed[j * rows + i] = matrix[i * cols + j]; //利用索引
        }
    }
    
    return transposed;
}